<?php

namespace Frieza\Modules\Position\Controllers;

use Doraemon\model\Position\PositionExtend;
use Doraemon\tools\ImgUrl;
use Encore\Admin\Grid;
use Encore\Admin\Widgets\Form;
use Illuminate\Http\Request;


class Tab4WelfareAgencyBannerController extends BaseController
{
    use BaseTrait;

    const TITLE_ARR = [
        'fine_goods_test' => '好好测',
        'new_product' => '新品速递',
        'others' => '其他',
    ];


    public function extendList(Grid $grid)
    {
        $grid->column('pos', '位置');
        $grid->column('ext->title', '标题')->display(function () {
            return ($this->ext)['title'] ?? '';
        })->width(100);
        $grid->column('ext->key_word', '副标题');
        $grid->column('pic_url', '图片')->image();
        $grid->column('single_pic_url', '自定义商品图')->image();
    }


    public function saveModule(Request $request, $baseInfoId)
    {
        $title = $request->input('title', '');
        $keyWord = $request->input('key_word', '');
        PositionExtend::saveOperationPos($baseInfoId, $title, $keyWord);
    }

    public function beforeTitleForm(Form $form)
    {
        $seed = range(1, 20);
        $form->select('base.pos', '位置')->options(array_combine($seed, $seed));
        $form->text('title', '标题')->placeholder('好好测,新品速递,其他')->required();
        $form->text('key_word', '副标题')->required();
        $form->imgUpload('base.pic_id', '图片', false,
            ['imgType' => ImgUrl::APPTYPE_OP, 'imgSize' => ImgUrl::IMAGE_SIZE_OP_ORI]);
        $form->imgUpload('base.single_pic_id', '自定义商品图', false,
            ['imgType' => ImgUrl::APPTYPE_OP, 'imgSize' => ImgUrl::IMAGE_SIZE_OP_ORI]);
    }

}
